{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "PRESET = os.environ.setdefault(\"PRESET\", \"test_spu_aggregator\")\n",
    "SELF_PARTY = os.environ.setdefault(\"SELF_PARTY\", \"sim\")\n",
    "os.environ[\"NODE_ENV\"] = \"development\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path\n",
    "import ray\n",
    "from opentelemetry import trace\n",
    "from opentelemetry.sdk.environment_variables import OTEL_SERVICE_NAME\n",
    "\n",
    "from secretnote.instrumentation.sdk import (\n",
    "    create_profiler,\n",
    "    inherit_tracing_context,\n",
    "    setup_tracing,\n",
    ")\n",
    "\n",
    "ray.shutdown()\n",
    "\n",
    "os.environ[OTEL_SERVICE_NAME] = f\"{PRESET}:{SELF_PARTY}\"\n",
    "\n",
    "setup_tracing()\n",
    "# setup_debug_exporter()\n",
    "\n",
    "\n",
    "with trace.get_tracer(__name__).start_as_current_span(\n",
    "    \"sim_trace\",\n",
    "    context=inherit_tracing_context(),\n",
    "):\n",
    "    with create_profiler() as profiler:\n",
    "        with open(f\"./presets/{PRESET}/_world.py\") as f:\n",
    "            _world = compile(f.read(), str(Path(f.name).resolve()), \"exec\")\n",
    "        with open(f\"./presets/{PRESET}/_algorithm.py\") as f:\n",
    "            _algorithm = compile(f.read(), str(Path(f.name).resolve()), \"exec\")\n",
    "        exec(_world, globals())\n",
    "        exec(_algorithm, globals())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from secretnote.display import visualize_run\n",
    "\n",
    "visualize_run(profiler)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
